package com.hntxk.cqzd.basicinfo.basepatient.action;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * page路径重定向的controller类
 *
 * @author Huang.Biquan
 * @date 2019年03月01日 下午3:23:16
 */
@WebServlet(urlPatterns = {"/page/cqzd/*"})
public class JspDirectController extends HttpServlet {

    private static final String URL_PREFIX = "/WEB-INF/view/";

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String requestUri = request.getRequestURI();
        Enumeration<String> parameterNames = request.getParameterNames();
        String name;
        while (parameterNames.hasMoreElements()){
            name = parameterNames.nextElement();
            request.setAttribute(name,request.getParameter(name));
        }
        requestUri = URL_PREFIX+requestUri.substring(6+request.getContextPath().length());

        request.getRequestDispatcher(requestUri).forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
